Skip to content

Conversation

@RiverDave
Copy link
Collaborator

@RiverDave RiverDave commented Nov 15, 2025

Bringing the changes we performed at: llvm/llvm-project#161028 down to the incubator isn't as straight-forward as I though. Therefore — this PR might be a bit long but hopefully not too complicated, bare with me :)

The main purpose of this is to bring the recent upstreamed TargetAddressSpaceAttr and couple it with PointerType and GlobalOp. The main challenge is that this collides with the already implemented infrastructure related to AS that revolves around our unified enum approach (That handles numeric and lang AS). My main rationale here is that we let our new attribute to coexist with the already existing cir::AddressSpaceAttr (renamed now). so that we don't break any tests related to offload-type languages.

Considering the above what I'm essentially doing is:

  1. Letting TargetAddressSpaceAttr handle numeric target AS as it is done upstream.
  2. Rename our previous AddressSpaceAttr to LangAdddressSpaceAttr.
  3. Implement MemorySpaceAttrInterfacefor lang and target AS.
  4. The current implementation of LangAddressSpaceAttr(which handles an enum) will handle language/clang specific AS (CUDA, OpenCL, etc..) it will no longer handle target as it used to!
  5. PointerType and globalOps will hold a MemorySpaceAttrInterface. Similar to the upstream ptr type in the ptr dialect.
  6. Adjusted the assembly format for all tests containing any AS attributes to conform with our new format: lang_address_space(n)/clang_address_space(x).
  7. For the relevant Ops: Default address spaces will now be represented as an empty MemorySpaceAttrInterface attribute.
  8. Remove any comments that make reference to our old approach regarding AS handling.
  9. Updated description where relevant.
  10. Bring any extra upstream changes that deviate with what we have here.

@RiverDave RiverDave changed the title [CIR][AddrSpace] Backport TargetAddressSpaceAttr and Support both language(clang) and target address-space attributes in pointer types and Global Ops [CIR] Backport TargetAddressSpaceAttr and Support both existing AS and target AS attributes in pointer types and Global Ops Nov 17, 2025
@github-actions
Copy link

github-actions bot commented Nov 19, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@RiverDave RiverDave changed the title [CIR] Backport TargetAddressSpaceAttr and Support both existing AS and target AS attributes in pointer types and Global Ops [CIR] Backport TargetAddressSpaceAttr and Support both existing Lang AS and target AS attributes in pointer types and Global Ops Nov 19, 2025
@RiverDave RiverDave marked this pull request as ready for review November 20, 2025 16:11
@bcardosolopes
Copy link
Member

I like the overall direction, thanks for taking the time to improve the holistic approach. One nit is to perhaps rename ClangAdddressSpaceAttr to LangAdddressSpaceAttr. Let's see if other reviewers have more insight here.

(cc @koparasy)

@koparasy
Copy link
Contributor

I like the overall direction, thanks for taking the time to improve the holistic approach. One nit is to perhaps rename ClangAdddressSpaceAttr to LangAdddressSpaceAttr. Let's see if other reviewers have more insight here.

(cc @koparasy)

I don’t have a strong objection to the implementation itself — the patch is clear and seems consistent with the upstream direction. My only hesitation is around the conceptual cost of introducing two separate address-space attributes. Address spaces are already a tricky area, and users can also influence them via language-level attributes, so reasoning about them tends to get complicated quickly.

Do we have a long-term plan for how TargetAddressSpaceAttr and ClangAddressSpaceAttr are expected to relate to each other? In particular, is the intention that these eventually converge (e.g., via a redesigned ClangAddressSpaceAttr or the MemorySpaceAttrInterface work), or do we expect them to remain distinct? Understanding the roadmap would help me see the benefit of keeping them separate rather than unifying the representation.

@RiverDave
Copy link
Collaborator Author

RiverDave commented Nov 21, 2025

I like the overall direction, thanks for taking the time to improve the holistic approach. One nit is to perhaps rename ClangAdddressSpaceAttr to LangAdddressSpaceAttr. Let's see if other reviewers have more insight here.
(cc @koparasy)

I don’t have a strong objection to the implementation itself — the patch is clear and seems consistent with the upstream direction. My only hesitation is around the conceptual cost of introducing two separate address-space attributes. Address spaces are already a tricky area, and users can also influence them via language-level attributes, so reasoning about them tends to get complicated quickly.

Do we have a long-term plan for how TargetAddressSpaceAttr and ClangAddressSpaceAttr are expected to relate to each other? In particular, is the intention that these eventually converge (e.g., via a redesigned ClangAddressSpaceAttr or the MemorySpaceAttrInterface work), or do we expect them to remain distinct? Understanding the roadmap would help me see the benefit of keeping them separate rather than unifying the representation.

Hey :) thanks for the comment, we initially had laid down support for it to be unified as it is currently down here in the incubator.

def CIR_AddressSpace : CIR_I32EnumAttr<

The decision to split both attributes came from feedback from one of the mantainers of the core mlir dialects. llvm/llvm-project#161028 (comment) (I'd suggest thoroughly looking at the discussion for full context). Our ultimate goal is to align with other upstream dialects, specifically the ptr dialect and how it attaches memory spaces to it. I think It is fair for both of them to remain distinct in CIR at least. They would converge on the lowering stage as LLVM ir can only represent numeric address spaces.

However, I think @xlauko and @andykaylor have more experience designing dialects and at the end — might have a better answer for you.

@bcardosolopes
Copy link
Member

bcardosolopes commented Nov 21, 2025

The decision to split both attributes came from feedback from one of the mantainers of the core mlir dialects.

Just want to point out that splitting is fine but it shouldn't come with the cost of code readability, having two attributes is super confusing (specially given the names aren't helping here). We should either go for the interface right away (unless there are good reasons to wait a bit more) or rename them a bit (like I suggested in the first comment) + share some of the properties for the sake of clear interfaces (passing the base around).

@RiverDave
Copy link
Collaborator Author

The decision to split both attributes came from feedback from one of the mantainers of the core mlir dialects.

Just want to point out that splitting is fine but it shouldn't come with the cost of code readability, having two attributes is super confusing (specially given the names aren't helping here). We should either go for the interface right away (unless there are good reasons to wait a bit more) or rename them a bit (like I suggested in the first comment) + share some of the properties for the sake of clear interfaces (passing the base around).

I understand. Got a clear way forward now, thanks a lot for the pointers ^^

@RiverDave
Copy link
Collaborator Author

RiverDave commented Nov 26, 2025

Okay, I hope the diff in this patch is not too intimidating :D

I've addressed the naming (Clang -> Lang) and Implemented MemorySpaceAttrInterface as requested. We're no longer generalizing attributes as we used to initially, I think It's much clearer now.

Regarding the implementations of each interface method, I think we can defer this for a later PR. I'm still not sure where these would fit into, I assume we would couple that with the verifiers on top of PointerType, but that's just my guess.

Will fix conflicts once approved.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM after some nits

@RiverDave RiverDave force-pushed the users/riverdave/backport-target-addrspace branch from 1dc9029 to 115c9f7 Compare November 26, 2025 23:02
@bcardosolopes bcardosolopes merged commit 2807a3e into main Nov 27, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants